package com.example.clientsideapplication;

import java.util.ArrayList;
import java.util.Map.Entry;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class ViewClientOfferActivity extends Activity {

	
	private ArrayList<Entry<Merchant, Offer>> offerArrayList;
	private ListView offerViewList;

	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_offer);

		Intent intent = getIntent();
		
		offerArrayList = (ArrayList<Entry<Merchant, Offer>>) intent.getSerializableExtra("offer");
		
		offerViewList = (ListView) findViewById(R.id.offer_list);
		offerViewList.setAdapter(new OfferClientListAdapter(this,
				R.layout.row_list_layout, offerArrayList));
		registerForContextMenu(offerViewList);
		offerViewList
				.setOnItemClickListener(new AdapterView.OnItemClickListener() {
					public void onItemClick(AdapterView parent, View v, int position, long id) {
						Entry<Merchant, Offer> item = offerArrayList.get(position);
						Intent intent = new Intent(
								ViewClientOfferActivity.this,
								ViewClientOfferInfo.class);
						intent.putExtra("merchant", item.getKey());
						intent.putExtra("offer", item.getValue());
						startActivity(intent);
					}
				});
	}
}
